# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)




find_package(Git)

#execute_process(
#    COMMAND ${GIT_EXECUTABLE} describe --abbrev=6 --dirty --always --tags
#    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
#    OUTPUT_VARIABLE  GIT_REPO_VERSION
#    OUTPUT_STRIP_TRAILING_WHITESPACE
#)

project(sadwinner)

set(PRJ_SRCS "")
set(PRJ_INC_DIR "")
set(PRJ_LIB idf::esp32 idf::freertos idf::spi_flash idf::nvs_flash idf::bt idf::console idf::vfs idf::fatfs idf::mqtt)
message("target-->:${TARGET}")
add_definitions(-DPRJ_NAME="${CMAKE_PROJECT_NAME}")
add_definitions(-DUSE_CYNOS_LIST=1)
add_definitions(-DPRJ_UNUSED)
#add_definitions(-DMBEDTLS_CONFIG_FILE='<mbedtls_config.h>')

if("${TARGET}" STREQUAL "esp32")
    # Include for ESP-IDF build system functions
    include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
    # Create idf::esp32 and idf::freertos static libraries
    message("==================Build Process Begin==================")
    idf_build_process(esp32
                    #COMPONENTS esp32 freertos esptool_py bt console vfs
                    SDKCONFIG ${CMAKE_CURRENT_LIST_DIR}/sdkconfig
                    BUILD_DIR ${CMAKE_BINARY_DIR})
    message("==================Build Process End==================")
                  
else()

endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)


message("==================User Code Begin==================")
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Src) 
include_directories(${PRJ_INC_DIR})
list (APPEND PRJ_INC_DIR "${CMAKE_BINARY_DIR}/libinclude/lvgl")
message(">>SRC:${PRJ_SRCS}")
message(">>INC:${PRJ_INC_DIR}")
message("==================User Code End==================")
set(elf_file ${CMAKE_PROJECT_NAME}.elf)
add_executable(${elf_file} ${PRJ_SRCS})

# Link the static libraries to the executable
if("${TARGET}" STREQUAL "esp32")
    target_link_libraries(${elf_file} ${PRJ_LIB})
    # Attach additional targets to the executable file for flashing,
    # linker script generation, partition_table generation, etc.
    idf_build_executable(${elf_file})
else()
    
endif()




